package com.smart.manager.pop.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.ArcoTips;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.Page;
import com.smart.manager.pop.entities.body.RDisInviter;
import com.smart.manager.pop.entities.models.PopDisInviter;
import com.smart.manager.pop.repository.DisInviterRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;


/**
 * @author Administrator
 */

@Api(tags = "分销人员管理")
@RestController
@RequestMapping(SmartConstant.MANAGER_API_PREFIX + "pop/dis/inviter")
@RequiredArgsConstructor
public class DisInviterApi {

    private final DisInviterRepository disInviterRepository;


    @GetMapping(value = "pageList")
    @ApiOperation(value = "查询分销人员")
    @SaCheckPermission("pop:dis:inviter:pageList")
    public AjaxResult<Page<PopDisInviter>> pageList(@Validated RDisInviter.SearchBody body) {
        Page<PopDisInviter> result = disInviterRepository.pageList(body);
        return AjaxResult.data(result);
    }


    @PostMapping(value = "add")
    @ApiOperation(value = "新增分销人员")
    @SaCheckPermission("pop:dis:inviter:add")
    public AjaxResult<String> add(@RequestBody @Validated RDisInviter.EditBody body) {
        disInviterRepository.add(body);
        return AjaxResult.success();
    }


    @PutMapping(value = "update/{id}")
    @ApiOperation(value = "修改分销人员")
    @SaCheckPermission("pop:dis:inviter:update")
    public AjaxResult<String> update(@PathVariable Long id, @RequestBody @Validated RDisInviter.EditBody body) {
        disInviterRepository.update(id, body);
        return AjaxResult.success();
    }


    @DeleteMapping(value = "delete")
    @ApiOperation(value = "删除分销人员")
    @SaCheckPermission("pop:dis:inviter:delete")
    public AjaxResult<Integer> delete(@RequestBody @NotEmpty(message = ArcoTips.PK_EMPTY) List<Long> ids) {
        int x = disInviterRepository.delByIds(ids);
        return AjaxResult.delSuccess(x);
    }


}
